package com.google.gwt.sample.contacts.client;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.fusesource.restygwt.client.MethodCallback;
import org.fusesource.restygwt.client.Resource;
import org.fusesource.restygwt.client.RestService;
import org.fusesource.restygwt.client.RestServiceProxy;

import com.google.gwt.core.client.GWT;
import com.google.gwt.sample.contacts.shared.Contact;
import com.google.gwt.sample.contacts.shared.ContactDetails;

public interface ContactsResourceAsync extends RestService {

	@POST
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public void addContact(Contact contact, MethodCallback<Contact> callback);

	@DELETE
	@Produces(MediaType.APPLICATION_JSON)
	public void deleteContacts(List<String> ids,
			MethodCallback<List<ContactDetails>> callback);

	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public void getContactDetails(MethodCallback<List<ContactDetails>> callback);

	@Path("/{id}")
	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public void getContact(@PathParam("id") String id,
			MethodCallback<Contact> callback);

	@PUT
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public void updateContact(Contact contact, MethodCallback<Contact> callback);

	public static final class Util {

		private static ContactsResourceAsync instance;

		public static final ContactsResourceAsync get() {
			if (instance == null) {
				instance = GWT.create(ContactsResourceAsync.class);
				Resource resource = new Resource("rest/contacts");
				((RestServiceProxy) instance).setResource(resource);
			}
			return instance;
		}

		private Util() {
		}
	}
}
